dojo.declare("MCustomerHomePg", wm.Page, {

    start: function() {
        this.vVendorMinAmount = 0;

        this.svProjectServices.input.setValue("projectId", wm.Page.getPage("MobileMainPg").vProjectId);
        this.svProjectServices.update();

    },
    "preferredDevice": "phone",
    displayHomePg: function() {



    },

    listProjectServicesCustomeraddressFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        if (inValue) {
            return inValue;
        } else {
            return "";
        }

    },
    tbLogoutClick: function(inSender) {
        this.ncLogout.update();
        var mainPage = wm.Page.getPage("MobileMainPg");
        mainPage.vLoginCount = mainPage.vLoginCount + 1;

        wm.Page.getPage("MobileMainPg").ncLoginPg.update();
        //mainPage.headerPanel.setShowing(true);
    },
    layerVendorItemsShow: function(inSender) {
        if (wm.Page.getPage("MCustomerOrderSelectPg")) {
            wm.Page.getPage("MCustomerOrderSelectPg").lvVendorItems.clearData();
            wm.Page.getPage("MCustomerOrderSelectPg").lvVendorItems.update();
        }

    },
    tbPastOrdersClick1: function(inSender) {
        if (wm.Page.getPage("MCustomerOrderHistoryPg")) {

            wm.Page.getPage("MCustomerOrderHistoryPg").loadHistory();
        }
        this.vPageBack = "CUSTOMER_HISTORY";
    },
    listProjectServicesSelect: function(inSender, inItem) {
        this.vPageBack = "VENDORS";
        // this.svProjectSvcVendors.input.setValue("projectId", wm.Page.getPage("MobileMainPg").vProjectId);
        // this.svProjectSvcVendors.update();
        this.layerVendors.activate();

    },
    layerVendorClosedShow: function(inSender) {
        this.layerVendorItemsShow(inSender);
    },

    checkVendorShopTime: function(inSender, inItem) {
        var selectedData = inSender.selectedItem.getData();
        this.vVendorMinAmount = selectedData.minOrderAmt;

        this.svShopTime.update();

    },

    svShopTimeSuccess: function(inSender, inDeprecated) {
        //  alert(inSender.getData().dataValue);
        var shopTime = inSender.getData().dataValue;
        var index = this.listProjectServices.getSelectedIndex();

        this.vPageBack = "VENDOR_ITEMS";


        if (index != -1) {
            var ptoVar = this.listProjectServiceVendors1.selectedItem.data.pto;
            var shopTimeValue = this.listProjectServiceVendors1.selectedItem.data.shopTime;
            var ptoMsg = this.listProjectServiceVendors1.selectedItem.data.ptoMessage;
            if (ptoMsg === null || ptoMsg.length === 0 || ptoMsg === "") {
                ptoMsg = "Shop is closed";
            }
            if (ptoVar) {

                this.layerVendorClosed.activate();
                this.labelVendorClosed.setCaption(ptoMsg);
            } else {
                if (shopTime) {
                    this.svItemCategory.update();
                    if (wm.Page.getPage("MCustomerOrderSelectPg")) {
                        wm.Page.getPage("MCustomerOrderSelectPg").layerSelectCategory.activate();
                    }
                    this.layerVendorItems.activate();

                } else {
                   
                    this.layerVendorClosed.activate();
                    this.labelVendorClosed.setCaption(ptoMsg);
                }

            }

        }
    },
    backClick: function(inSender) {

        if (this.vPageBack === 'VENDORS') {

            this.layerServices.activate();

        }
        if (this.vPageBack === 'VENDOR_ITEMS') {
            this.layerVendors.activate();
            this.vPageBack = 'VENDORS';

        }
        if (this.vPageBack === 'VENDOR_ITEM_CATEGORY') {
            if (wm.Page.getPage("MCustomerOrderSelectPg")) {
                wm.Page.getPage("MCustomerOrderSelectPg").layerSelectCategory.activate();
            }
            this.vPageBack = 'VENDOR_ITEMS';

        }
        if (this.vPageBack === 'CHECK_OUT') {

            if (wm.Page.getPage("MCustomerOrderSelectPg")) {
                wm.Page.getPage("MCustomerOrderSelectPg").layerSelectOrder.activate();
            }
            this.vPageBack = 'VENDOR_ITEM_CATEGORY';
        }

        if (this.vPageBack === 'CONFIRM_ORDER') {

            if (wm.Page.getPage("MCustomerOrderSelectPg")) {
                wm.Page.getPage("MCustomerOrderSelectPg").refreshVendorItemList();
                wm.Page.getPage("MCustomerOrderSelectPg").txtSearch.clear();
                wm.Page.getPage("MCustomerOrderSelectPg").layerSelectOrder.activate();
            }
            this.vPageBack = 'VENDOR_ITEM_CATEGORY';
        }
        if (this.vPageBack === 'CUSTOMER_HISTORY') {
            this.layerOrderHistory.activate();
            if (wm.Page.getPage("MCustomerOrderHistoryPg")) {
                wm.Page.getPage("MCustomerOrderHistoryPg").layerOrders.activate();
            }

        }

        if (this.vPageBack === 'CUSTOMER_ACCOUNT') {
            this.layerMyAccount.activate();


        }


    },
    tbServicesClick1: function(inSender) {

        this.vPageBack = "VENDORS";
    },
    tbUpdateAccountClick1: function(inSender) {
        this.vPageBack = "CUSTOMER_ACCOUNT";
    },
    listProjectServicesServiceIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var buttonText = '<img src ="resources/images/mobile/next_img.png" height="26px" />';
        return buttonText;
    },
    listProjectServiceVendorsServiceIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var buttonText = '<img src ="resources/images/mobile/next_img.png" height="26px" />';
        return buttonText;
    },
    listProjectServiceVendors1Select: function(inSender, inItem) {
        // this.listProjectServiceVendorsSelect(inSender, inItem);
    },
    listProjectServicesSelect1: function(inSender, inItem) {
        var serviceId = this.listProjectServices.selectedItem.data.serviceId;

        this.listProjectServiceVendors1.setDataSet(this.svProjectAllVendors.setQuery({
            serviceId: serviceId
        }));


    },
    svProjectAllVendorsSuccess: function(inSender, inDeprecated) {

    },

    _end: 0
});